//
//  NSObject+Util.m
//  CarUser
//
//  Created by ayi on 2018/12/24.
//  Copyright © 2018 王森林. All rights reserved.
//

#import "NSObject+Util.h"

@implementation NSObject (Util)

- (void)verificationKeyAndSettingNewVauleWitKey:(NSString * _Nonnull )key WithNewVaule:(id _Nonnull)vaule{
    if (key == nil || vaule == nil) {
        return;
    }
    unsigned int outCount;
    objc_property_t *properties = class_copyPropertyList([self class], &outCount);
    for (int i = 0; i < outCount; i++) {
        objc_property_t property = properties[i];
        const char * name = property_getName(property);
        NSString *propertyName = [NSString stringWithCString:name encoding:NSUTF8StringEncoding];
        if ([propertyName isEqualToString:key]) {
            [self setValue:vaule forKey:key];
            break;
        }
    }
    free(properties);
}

@end
